﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditorInternal;

namespace Nirvana
{
    [CustomEditor(typeof(AudioImportRule), true)]
    public class AudioImportRuleEditor : Editor
    {
        private SerializedProperty includeRegexs;
        private SerializedProperty excludeRegexs;
        private SerializedProperty importAudio1, importAudio2, importAudio5;

        bool isHold1 = false, isHold2 = false, isHold5 = false;

        public override void OnInspectorGUI()
        {
            base.serializedObject.Update();
            GUILayout.Label("匹配规则", GUITheme.LabelTitleStyle);
            GUILayoutEx.BeginContents();
            GUI.color = Color.yellow;
            EditorGUILayout.HelpBox("注意：规则文件只会检测同一父目录或同一级目录下的资源。\n\n" +
                "正则例子：1.匹配非空字符：\\S , 2.任意字符：. ", MessageType.None);
            GUI.color = Color.white;
            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(this.includeRegexs);
            EditorGUILayout.PropertyField(this.excludeRegexs);

            GUILayoutEx.EndContents();
            EditorGUILayout.Space();

            //说明
            GUILayout.Label("配置策略", GUITheme.LabelTitleStyle);
            //GUI.color = Color.green;
            EditorGUILayout.HelpBox("音频处理分为三个级别：短音频(1s以内)，中长音频(1s-5s),长音频(5s以上)\n\n" +
                "1s以内的音频: Load Type = DecompressOnLoad；compressionFormat = ADPCM；preloadAudioData = true; loadInBackground = false；\n\n" +
                "1s - 5s的音频: Load Type = CompressedInMemory；compressionFormat = ADPCM；preloadAudioData = false; loadInBackground = false \n\n" +
                "5s以上的音频: Load Type = Streaming；compressionFormat = Vorbis；quality = 0.7f；preloadAudioData = false; loadInBackground = true\n", MessageType.None);
            GUI.color = Color.white;
            EditorGUILayout.Space();
            EditorGUILayout.Space();


#if UNITY_2019_1_OR_NEWER
            isHold1 = EditorGUILayout.BeginFoldoutHeaderGroup(isHold1, "1秒内短音频导入规则设置");
            if (isHold1)
            {
                EditorGUILayout.PropertyField(this.importAudio1);
            }
            EditorGUILayout.EndFoldoutHeaderGroup();

            EditorGUILayout.Space();
            isHold2 = EditorGUILayout.BeginFoldoutHeaderGroup(isHold2, "1~5秒内中音频导入规则设置");
            if (isHold2)
            {
                EditorGUILayout.PropertyField(this.importAudio2);
            }
            EditorGUILayout.EndFoldoutHeaderGroup();

            EditorGUILayout.Space();
            isHold5 = EditorGUILayout.BeginFoldoutHeaderGroup(isHold5, "5秒以上背景音导入规则设置");
            if (isHold5)
            {
                EditorGUILayout.PropertyField(this.importAudio5);
            }
            EditorGUILayout.EndFoldoutHeaderGroup();
#else
            isHold1 = EditorGUILayout.Foldout(isHold1, "1秒内短音频导入规则设置");
            if (isHold1)
            {
                EditorGUILayout.PropertyField(this.importAudio1);
            }

            EditorGUILayout.Space();
            isHold2 = EditorGUILayout.Foldout(isHold2, "1~5秒内中音频导入规则设置");
            if (isHold2)
            {
                EditorGUILayout.PropertyField(this.importAudio2);
            }

            EditorGUILayout.Space();

            isHold5 = EditorGUILayout.Foldout(isHold5, "5秒以上背景音导入规则设置");
            if (isHold5)
            {
                EditorGUILayout.PropertyField(this.importAudio5);
            }

            EditorGUILayout.Space();
#endif
            base.serializedObject.ApplyModifiedProperties();
        }

        private void OnEnable()
        {
            if (this.target == null)
            {
                return;
            }
            SerializedObject serializedObject = base.serializedObject;
            this.includeRegexs = serializedObject.FindProperty("includeRegexs");
            this.excludeRegexs = serializedObject.FindProperty("excludeRegexs");
            this.importAudio1 = serializedObject.FindProperty("importAudio1");
            this.importAudio2 = serializedObject.FindProperty("importAudio2");
            this.importAudio5 = serializedObject.FindProperty("importAudio5");

        }

    }
}

